package com.flying.client.ui;

import java.io.UnsupportedEncodingException;

import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;

import com.flying.client.network.IMsgHandler;
import com.flying.client.network.msg.ORMsg;
import com.flying.client.network.msg.OWMsg;
import com.flying.client.utils.Logger;

public class InitSessionHandler implements IMsgHandler{

	private static final Logger logger = Logger.getLogger(InitSessionHandler.class.getName());
	
	public void onMsg(ORMsg rMsg)
	{
		logger.debug("onMsg rMsg");
		
		ChannelBuffer buffer = rMsg.getMsgContent();
		int len = buffer.readInt();
		logger.debug("len = "+len);
		ChannelBuffer sessionBuffer = ChannelBuffers.dynamicBuffer(len);
		buffer.readBytes(sessionBuffer,len);
		
		byte[] bytes = sessionBuffer.array();
		
		try {
			String sessionID = new String(bytes,"UTF-8");
			logger.debug("sessionID = "+ sessionID);
		} catch (UnsupportedEncodingException e) {
			logger.debug("oMsg error="+e);
		}
	}
	
	public static OWMsg createWMsg()
	{
		OWMsg wMsg = new OWMsg(MsgType.INIT);
		wMsg.setMsgSeq((short)1);
		
		return wMsg;
	}

}
